package ar.com.sistventa.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;

import ar.com.sistventa.dao.CajaDAO;
import ar.com.sistventa.entities.Caja;

public class CajaDAOImpl extends EntidadDAOImpl<Caja> implements CajaDAO {

	@Override
	public Caja getCajaByNumeroCaja(Long numeroCaja) throws HibernateException {
		Caja caja = null;

		try {
			iniciaConexion();
			Criteria criteria = getSession().createCriteria(Caja.class);
			criteria.add(Restrictions.eq("numeroCaja", numeroCaja));
			caja = (Caja) criteria.uniqueResult();

		} catch (HibernateException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.getSession().close();
		}
		return caja;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Caja> getCajaByEstado(boolean estado) throws HibernateException {
		List<Caja> cajaList = new ArrayList<Caja>();

		try {
			iniciaConexion();
			Criteria criteria = getSession().createCriteria(Caja.class);
			criteria.add(Restrictions.eq("cerrado", estado));
			cajaList = (List<Caja>) criteria.list();

		} catch (HibernateException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.getSession().close();
		}
		return cajaList;
	}

	@Override
	public Caja getUltimaCaja() throws HibernateException {
		// TODO Auto-generated method stub
		return null;
	}

}
